{extend name="base" /}

{block name="content"}
<form class="layui-form" action="" id="searchBox">
    <div class="layui-inline">
        <select name="game_id" lay-filter="game_id" id="game_id" lay-verify="required" lay-search="">
            <option value="">游戏名称（全部）</option>
            {volist name="$game_id" id="vo"}
            <option value="{$vo.game_id}">{$vo.game_id}：{$vo.game_name}</option>
            {/volist}
        </select>
    </div>
    <div class="layui-inline">
        <select name="app_class_id" lay-filter="app_class_id" id="app_class_id" lay-verify="required" lay-search="">
            <option value="">游戏属性（全部）</option>
            {volist name="$app_class_id" id="vo"}
            <option value="{$vo.id}">{$vo.id}：{$vo.name}</option>
            {/volist}
        </select>
    </div>
    <div class="layui-inline">
        <select name="app_publish_type_id" lay-filter="app_publish_type_id" id="app_publish_type_id" lay-verify="required" lay-search="">
            <option value="">游戏版本（全部）</option>
            {volist name="$app_publish_type_id" id="vo"}
            <option value="{$vo.id}">{$vo.id}：{$vo.name}</option>
            {/volist}
        </select>
    </div>
    <div class="layui-inline">
        <select name="app_platform_type_id" lay-filter="app_platform_type_id" id="app_platform_type_id" lay-verify="required" lay-search="">
            <option value="">游戏平台（全部）</option>
            {volist name="$app_platform_type_id" id="vo"}
            <option value="{$vo.id}">{$vo.id}：{$vo.name}</option>
            {/volist}
        </select>
    </div>
    <div class="layui-inline">
        <a href="javascript:;" class="layui-btn searchBtn my-btn my-btn-sm">搜索</a>
        <a href="javascript:;" class="layui-btn my-btn my-btn-sm" id="refresh">刷新</a>
    </div>
</form>

<table id="tableBox" lay-filter="tableBox"></table>

<script type="text/html" id="tableBar">
    {{#  if(d.msg === '上传完成'){ }}
    <button class="layui-btn layui-btn-sm" lay-event="down">下载</button>
    <span class="layui-my-span layui-btn-sm layui-btn-disabled" disabled>打包</span>
    <button class="layui-btn layui-btn-sm" lay-event="repeat">重打包</button>
    {{#  } else { }}
    <span class="layui-my-span layui-btn-sm layui-btn-disabled" disabled>下载</span>
        {{#  if(d.app_client_type_id === 4){ }}
        <span class="layui-my-span layui-btn-sm layui-btn-disabled" disabled>打包</span>
        {{#  } else { }}
        <button class="layui-btn layui-btn-sm" lay-event="pack">打包</button>
        {{#  } }}
    <span class="layui-my-span layui-btn-sm layui-btn-disabled" disabled>重打包</span>
    {{#  } }}
</script>

<script type="text/html" id="downloadTpl">
    <input type="text" value="{{ d.download }}" class="layui-input download">
</script>
{/block}

{block name="css"}
<style>
    table {border-collapse: separate;}
    tbody .layui-table-cell {padding-left: 8px; padding-right:8px;line-height: 52px; height: 52px;}
    .layui-my-span {height: 26px; line-height: 26px; padding-top:5px; padding-bottom: 5px; margin-left:0;}
    .layui-btn + .layui-btn {margin-left:0;}
    thead .layui-table-cell {}
</style>
{/block}

{block name="js"}
<script>
    layui.use('table', function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,load = layer.load()
            ,active = {
                reload: function () {
                    var jsonObj = {
                        "game_id": $('#game_id').val()
                        ,"app_class_id": $('#app_class_id').val()
                        ,"app_publish_type_id": $('#app_publish_type_id').val()
                        ,"app_platform_type_id": $('#app_platform_type_id').val()
                    };

                    table.reload('tableId', {
                        page: {curr: 1}
                        ,where: jsonObj
                        ,height: 'full-80'
                    })
                }
            };

        //表格初始化
        table.render({
            elem: '#tableBox'
            ,height: 'full-80'
            ,url: '{:url("GameList/index")}'
            ,page: true
            ,limit:20
            ,limits:[20,40,60,80]
            ,loading:true
            ,id:'tableId'
            ,done: function () {
                layer.close(load);
            }
            ,cols: [[
                {field:'icon', title: '图标', width: 65}
                ,{field:'game_id', title: '游戏ID', width: 75}
                ,{field:'game_name', title: '游戏名称', width: 150}
                ,{field:'app_class_id', title: '游戏属性', width: 90}
                ,{field:'app_publish_type_id', title: '游戏版本', width: 90}
                ,{field:'package_size', title: '游戏大小', width: 90}
                ,{field:'version_str', title: '游戏版号', width: 90}
//                ,{field:'online_time_region', title: '上线时间', width: 150}
                ,{field:'download', title: '下载地址', width: 600, templet: '#downloadTpl'}
                ,{field:'msg', title: '打包状态', width: 90}
                ,{title: '操作', align:'center', toolbar:'#tableBar'}
            ]]
        });


        $('#searchBox .searchBtn').on('click', function(){
            load = layer.load();
            active['reload'].call(this);
            return false;
        });

        $('#refresh').click(function(){
            window.location.reload();
        })

        $('body').on('click', ".download", function(){
            $(this).select();
        });


        //监听工具条
        table.on('tool(tableBox)', function(obj){
            var data = obj.data;
            if(obj.event === 'pack'){
                layer.confirm('"'+data.game_name+'" 进行打包吗？', {offset: '250px'}, function(index){
                    $.post('{:url("GameList/pack")}',{game_id: data.game_id}, function(json){
                        if(json.code==0){
                            layer.msg(json.msg, {icon: 1, time:3000})
                        }else{
                            layer.msg(json.msg, {icon: 0, time:3000});
                        }
                    }, 'JSON').error(function(){
                        layer.close(load);
                        layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
                    });
                });
            }else if(obj.event === 'down'){
                layer.confirm('"'+data.game_name+'" 进行下载吗？', {offset: '250px'}, function(index){
                    window.location.href = data.download;
                });
            }else if(obj.event === 'repeat'){
                layer.confirm('"'+data.game_name+'" 进行重打包吗？', {offset: '250px'}, function(index){
                    $.post('{:url("GameList/pack")}',{game_id: data.game_id}, function(json){
                        if(json.code==0){
                            layer.msg(json.msg, {icon: 1, time:3000})
                        }else{
                            layer.msg(json.msg, {icon: 0, time:3000});
                        }
                    }, 'JSON').error(function(){
                        layer.close(load);
                        layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
                    });
                });
            }
        });
    });
</script>
{/block}